package com.hxzf.mvp.commons.db;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hxzf.mvp.commons.constant.SysConstant;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

/**
 * 审计字段自动填充
 *
 * @author Kai
 * @date 2021/6/23 15:08
 **/
public class AuditingMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Date now = new Date();
        this.strictInsertFill(metaObject, SysConstant.DEFAULT_CREATE_TIME_FIELD, Date.class, now);
        this.strictInsertFill(metaObject, SysConstant.DEFAULT_UPDATE_TIME_FIELD, Date.class, now);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, SysConstant.DEFAULT_UPDATE_TIME_FIELD, Date.class, new Date());
    }
}
